package com.java110.mall.goods.bmo.housekeepingType.impl;

import com.java110.core.annotation.Java110Transactional;
import com.java110.dto.file.FileDto;
import com.java110.dto.housekeeping.HousekeepingTypeDto;
import com.java110.mall.goods.bmo.housekeepingType.IUpdateHousekeepingTypeBMO;
import com.java110.intf.system.IFileInnerServiceSMO;
import com.java110.intf.goods.IHousekeepingTypeInnerServiceSMO;
import com.java110.po.housekeeping.HousekeepingTypePo;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service("updateHousekeepingTypeBMOImpl")
public class UpdateHousekeepingTypeBMOImpl implements IUpdateHousekeepingTypeBMO {

    @Autowired
    private IHousekeepingTypeInnerServiceSMO housekeepingTypeInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;

    /**
     * @param housekeepingTypePo
     * @return 订单服务能够接受的报文
     */
    @Java110Transactional
    public ResponseEntity<String> update(HousekeepingTypePo housekeepingTypePo) {

        if (!"9999".equals(housekeepingTypePo.getShopId()) && StringUtil.isEmpty(housekeepingTypePo.getTypeCd())) {
            housekeepingTypePo.setTypeCd(HousekeepingTypeDto.TYPE_CD_HOUSEKEEPING);
        }
        if(!StringUtil.isEmpty(housekeepingTypePo.getHktIcon()) && housekeepingTypePo.getHktIcon().length()> 512) {
            FileDto fileDto = new FileDto();
            fileDto.setContext(housekeepingTypePo.getHktIcon());
            fileDto.setFileName(housekeepingTypePo.getHktId());
            String fileName = fileInnerServiceSMOImpl.saveFile(fileDto);
            housekeepingTypePo.setHktIcon(fileName);
        }

        int flag = housekeepingTypeInnerServiceSMOImpl.updateHousekeepingType(housekeepingTypePo);

        if (flag > 0) {
            return ResultVo.createResponseEntity(ResultVo.CODE_OK, "保存成功");
        }

        return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
    }

}
